﻿CREATE PROCEDURE [dbo].[StoreDigitalSensor]
	@SensorId bigint,
  @SensorType int,
	@Created datetimeoffset,	
  @Value bit
AS
  begin transaction

  if not exists (select Id from Sensor where Id = @SensorId)
    begin
      insert Sensor (Id, Name) values (@SensorId, 'Unnamed')
    end 

  insert DigitalSensor(SensorId, SensorType, Created, Value)
  values (@SensorId, @SensorType, @Created, @Value)
	
  commit